package com.sanjiahantang.youjiaclient.module.cases.models.impl;

import android.content.Context;


import com.sanjiahantang.youjiaclient.base.BaseBean;
import com.sanjiahantang.youjiaclient.base.CallBack;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.http.BaseDelegate;
import com.sanjiahantang.youjiaclient.http.OkHttpClientManager;
import com.sanjiahantang.youjiaclient.module.cases.beans.CaseBean;
import com.sanjiahantang.youjiaclient.module.cases.beans.DesignerBean;
import com.sanjiahantang.youjiaclient.module.cases.models.ICaseModel;
import com.sanjiahantang.youjiaclient.module.cases.views.CaseView;
import com.sanjiahantang.youjiaclient.module.common.beans.ConditionBean;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by zy on 2017/9/5.
 */

public class CaseModel implements ICaseModel {
    @Override
    public void loadFavoriteCase(final Context context, Map<String, Object> param, final CallBack<CaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/customer/searchCollectForCaseInfo", param, new BaseDelegate.ResultCallback<CaseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void loadSelectors(final Context context, Map<String, String> params, final CallBack<ConditionBean> callBack, Object tag) {
        if ((int) tag == CaseView.TYPE_ADDRESS){
            OkHttpClientManager.postJson(context, ConfigValue.API_URL +  "/case/phone/customer/findCaseAddress", new HashMap<String, Object>(), new BaseDelegate.ResultCallback<ConditionBean>() {

                @Override
                public void onError(Request request, Object tag, Exception e) {
                    callBack.onFailure(e.getMessage());
                }

                @Override
                public void onResponse(ConditionBean response, Object tag) {
                    callBack.onSuccess(response, context, tag);
                }
            }, tag);
        }else{
            OkHttpClientManager.postAsyn(context, ConfigValue.API_URL +  "/system/dic/findDicByParentForPhone", params, new BaseDelegate.ResultCallback<ConditionBean>() {

                @Override
                public void onError(Request request, Object tag, Exception e) {
                    callBack.onFailure(e.getMessage());
                }

                @Override
                public void onResponse(ConditionBean response, Object tag) {
                    callBack.onSuccess(response, context, tag);
                }
            }, tag);
        }


    }


    @Override
    public void loadCaseByCondition(final Context context, Map<String, Object> params, final CallBack<CaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/case/phone/customer/searchCaseInfo", params, new BaseDelegate.ResultCallback<CaseBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void loadCaseById(final Context context, Map<String, Object> param, final CallBack<CaseBean.DetailBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/case/phone/customer/findCaseInfo", param, new BaseDelegate.ResultCallback<CaseBean.DetailBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean.DetailBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void loadDesignerInfo(final Context context, Map<String, String> param, final CallBack<DesignerBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/customer/findDesignInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void addCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/customer/addCollectInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void deleteCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/customer/deleteCollectInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void saveSelBidRequireInfoForCustomer(final Context context, Map<String, String> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/customerRequireBid/saveSelBidRequireInfoForCustomer", param, new BaseDelegate.ResultCallback<BaseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(BaseBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }
}
